package hc.bre

import static org.junit.jupiter.api.Assertions.*

import org.junit.jupiter.api.Test

import hc.bre.policy.ReasonDefinition

class PolicyReasonTest {

	@Test
	void buildAndEvaluate() {
		String jsonText ='''
{
  "rid" : 64,
  "rtype" : "data:policy:reason",
  "rname" : "政策及原因码",
  "rpath" : "xsxdjc/policy/RuleCodeSet",
  "rversion" : 29,
  "rmemo" : "",
  "rtest" : "{}",
  "rmaxid" : null,
  "list" : [ {
    "id" : 1,
    "code" : "R0001",
    "name" : "严格检查性别",
    "type" : "script",
    "script" : "个人信息.性别 == 1"
  }, {
    "id" : 2,
    "code" : "R0002",
    "name" : "始终命中",
    "type" : "script",
    "script" : "true"
  }, {
    "id" : 3,
    "code" : "R0003",
    "name" : "始终不命中",
    "type" : "script",
    "script" : "false"
  }, {
    "id" : 4,
    "code" : "R0004",
    "name" : "其它原因码",
    "type" : "manual",
    "script" : "true"
  }, {
    "id" : 5,
    "code" : "R0005",
    "name" : "",
    "type" : "manual",
    "script" : ""
  } ]
}
'''
		ReasonDefinition ruleDef = new ReasonDefinition();
		def json = hc.Util.jsonRead(jsonText);
		ruleDef.load(json);
		
//		println ruleDef.buildRuleScript();
//
//		ruleDef.buildRuleClass()

		def ret = ruleDef.buildRuleEvaluate([个人信息:[性别:2],_reasoncode_:'_all_']);
		assert ret.result.policyset.size() ==2 ;
		assert ret.result.policyset[0].code == 'R0002' ;
		assert ret.result.policyset[0].name == '始终命中' ;
		assert ret.result.policyset[1].id == 4 ;
	}
}
